import { login } from '@/api/user'
import { getToken, setToken, removeToken } from '@/utils/auth'
export default {
  namespaced: true,
  state: {
    token: getToken() || ''
  },
  mutations: {
    setToken(state, token) {
      state.token = token
      setToken(token)
    },
    delToken(state) {
      state.token = ''
      removeToken()
    }
  },
  actions: {
    async userLogin(context, payload) {
      const data = await login(payload)
      console.log(data)
      context.commit('setToken', data.data)
    }
  }
}
